<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>退货</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/js/my.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-body">
    <form class="layui-form" id="returnForm">
        <div class="layui-form-item">
            <label for="outId" class="layui-form-label">出库编号</label>
            <div class="layui-input-inline">
                <input id="outId" th:value="${reInfo.outId}"  name="outId" required=""
                       autocomplete="off" class="layui-input" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="productName" class="layui-form-label">产品名称</label>
            <div class="layui-input-inline">
                <input type="text" id="productName"th:value="${reInfo.productName}" name="productName" required="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="returnDate" class="layui-form-label">退货日期</label>
            <div class="layui-input-inline">
                <input id="returnDate"  name="returnDate" required=""  class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="returnQuantity" class="layui-form-label">退货数量</label>
            <div class="layui-input-inline">
                <input type="text" id="returnQuantity" th:value="${reInfo.outQuantity}" name="returnQuantity" required="" lay-verify="returnQuantity"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="clientName" class="layui-form-label">客户</label>
            <div class="layui-input-inline">
                <input type="text" id="clientName" th:value="${reInfo.clientName}" name="clientName" required=""
                       autocomplete="off" class="layui-input">
            </div>

        <div class="layui-form-item">
            <label for="returnReason" class="layui-form-label">退货原因</label>
            <div class="layui-input-inline">
                <input type="text" id="returnReason" name="returnReason" required="" autocomplete="off" class="layui-input" >
            </div>
        </div>

        <div class="layui-form-item">
            <label for="returnAmount" class="layui-form-label">退货总金额</label>
            <div class="layui-input-inline">
                <input type="text" id="returnAmount" th:value="${reInfo.outAmount}" name="returnAmount" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>

            <div class="layui-form-item">
                <label for="warehouseName" class="layui-form-label">仓库名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="warehouseName" th:value="${reInfo.warehouseName}" name="warehouseName" required=""
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="administrator" class="layui-form-label">仓库管理员</label>
                <div class="layui-input-inline">
                    <input type="text" id="administrator"th:value="${reInfo.administrator}" name="administrator" required="" autocomplete="off" class="layui-input" oninput="getAdministrator()">
                </div>
            </div>


        <div class="layui-form-item">
            <label  class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="returnPurchase" lay-submit="">
                退货
            </button>
        </div>
    </form>
</div>
</body>
</html>
<script>

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#returnDate' //指定元素
        });
    });

    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            returnNum: function(value) {
                //创建一个正则表达式对象
                var re = /^[0-9]*$/;
                //验证用户输入的入库数量是否是数字
                if (!re.test(value)) {
                    layer.alert("退货数量必须为数字！")
                }
            }
        });
        //退货
        form.on('submit(productReturn)', function(data){
            console.log(data);
            $.ajax({
                url:"/outOfStorage/productReturnAjax",
                type:"post",
                data:data.field,
                dataType:"json",//返回的数据类型
                success:function(data){
                    //定义{info:"退货成功"}
                    $("#info").text(data);
                    if(data.info == "退货成功"){
                        layer.alert("退货成功",function(index) {
                            //关闭弹窗操作
                            //获取Frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭弹窗
                            parent.layer.close(index);
                        });
                    }else{
                        layer.alert("退货失败");
                    }
                }
            })
            return false;
        });
    });
</script>